﻿using System.Linq.Expressions;

using Tszy.Unlimited.Data.AdoNet.Sql.Components.Visitors;

namespace Tszy.Unlimited.Data.AdoNet.Sql.Components.Expressions.Where
{
    /// <summary>
    /// WHERE 表达式处理器。
    /// </summary>
    internal interface IWhereExpressionHandler
    {
        /// <summary>
        /// 执行。
        /// </summary>
        /// <param name="context">上下文。</param>
        /// <param name="expression">表达式。</param>
        /// <returns>处理结果。</returns>
        WhereExpressionResult Execute(ExpressionContext context, Expression expression);

        /// <summary>
        /// 获得表达式类型。
        /// </summary>
        /// <returns>表达式类型。</returns>
        ExpressionType GetExpressionType();
    }

    /// <summary>
    ///
    /// </summary>
    internal abstract class WhereExpressionHandlerBase : IWhereExpressionHandler
    {
        /// <summary>
        ///
        /// </summary>
        protected IEvaluator Evaluator { get; } = new CacheEvaluator();

        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public abstract WhereExpressionResult Execute(ExpressionContext context, Expression expression);

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public abstract ExpressionType GetExpressionType();
    }
}